package com.yhsimon.distributed_lock.controller;

import com.yhsimon.distributed_lock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author： YHSimon
 * @date： 2022-09-03 21:25
 */
@RestController
@RequestMapping("/stock")
public class StockController {
    @Autowired
    private StockService stockService;

    @GetMapping("/deduct")
    public String deduct() {
        stockService.deduct();
        return "hello stock deduct";
    }


    @GetMapping("/test/read/lock")
    public String testReadLock(){
        stockService.testReadLock();
        return "hello read lock";
    }

    @GetMapping("/test/write/lock")
    public String testWriteLock(){
        stockService.testWriteLock();
        return "hello write lock";
    }

    @GetMapping("/test/semaphore")
    public String testSemaphore(){
        stockService.testSemaphore();
        return "hello semaphore";
    }
}
